<template>
  <div v-show="isShow" class="panel-right-close-btn" :class="[collapse && 'collapse']"></div>
</template>

<script setup>
import { useAddEventListener } from '@/hooks/useAddEventListener'
import { ref, toRefs } from 'vue'

const props = defineProps({
  threshold: {
    type: Number,
    default: 1756
  },
  collapse: {
    type: Boolean,
    default: false
  }
})

const { threshold, collapse } = toRefs(props)

const isShow = ref(false)
const handleMouseMove = ({ clientX }) => {
  if (window.innerWidth - clientX < threshold.value) {
    isShow.value = true
  } else {
    isShow.value = false
  }
}

useAddEventListener(window, 'mousemove', handleMouseMove)
</script>

<style scoped>
.panel-right-close-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  z-index: var(--side-panel-in-z-index);
  top: 50%;
  right: 6px;
  width: 60px;
  height: 100px;
  background: rgba(17, 37, 87, 0.88);
  border-radius: 20px;
  border: 4px solid rgba(0, 255, 229, 0.4);
  cursor: pointer;
}

.panel-right-close-btn:before {
  content: '';
  position: absolute;
  border: 20px solid transparent;
  border-left-color: #ffffff;
  border-right: 0;
}

.panel-right-close-btn.collapse:before {
  border-left: 0;
  border-right: 20px solid #ffffff;
}
</style>
